#include<iostream>
using namespace std;

int main()
{
	string s;
	cin >> s;
	int m;
	cin >> m;
	int arr[2];
	char str[2];
	while(m--)
	{
		for (size_t i = 0; i < 2; i++)
		{
			cin >> arr[i];
		}
		for (size_t i = 0; i < 2; i++)
		{
			cin >> str[i];
		}
		for (size_t i = arr[0] - 1; i <= arr[1] - 1; i++)
		{
			if (s[i] == str[0])
				s[i] = str[1];
		}
	}
	cout << s;
	return 0;
}